/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import DAO.util.ConectaBanco;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import model.Administrador;
import model.Login;


/**
 *
 * @author Alex
 */
public class AdministradorDAO {

    public boolean validarLogin(Login login) throws SQLException {

        Connection conexao = null;
        try {
            conexao = ConectaBanco.getConexao();
            String sql = "select id from administrador where id_login=?";

            PreparedStatement pst = conexao.prepareStatement(sql);

            pst.setInt(1, login.getId());
            ResultSet rs = pst.executeQuery();
            
            int id=0;
            while (rs.next()){
            id = rs.getInt("id");
            }
            conexao.close();
             if (id!=0){
             return true;
             }else{
             return false;
             }
          

        } catch (SQLException sql) {
            System.out.println("Erro ao buscar o time" + sql.getMessage());

            return false;
        }

    }

    public Administrador buscarPorIdLogin(Login login) {

        Connection conexao = null;
        try {
            conexao = ConectaBanco.getConexao();
            String sql = "select * from administrador where id_login=?";

            PreparedStatement pst = conexao.prepareStatement(sql);

            pst.setInt(1, login.getId());
            ResultSet rs = pst.executeQuery();
            Administrador administrador = new Administrador();
            while (rs.next()) {

                administrador.setId(rs.getInt("id"));
                administrador.setNome(rs.getString("nome"));
                administrador.setEmail(rs.getString("email"));
                administrador.setLogin(login);

            }
            conexao.close();
            return administrador;

        } catch (Exception sql) {
            System.out.println("Erro ao buscar o time" + sql.getMessage());
            return null;
        }

    }

}
